namespace Shumei.EFCore.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class init : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Courses",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 50, storeType: "nvarchar"),
                        CourseDes = c.String(nullable: false, unicode: false),
                        TeachId = c.String(nullable: false, maxLength: 20, storeType: "nvarchar"),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.TeachId, cascadeDelete: true)
                .Index(t => t.TeachId);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        account = c.String(nullable: false, maxLength: 20, storeType: "nvarchar"),
                        password = c.String(nullable: false, unicode: false),
                        name = c.String(nullable: false, maxLength: 20, storeType: "nvarchar"),
                        sex = c.Int(nullable: false),
                        headIcon = c.String(unicode: false),
                        Role = c.Int(nullable: false),
                        regTime = c.DateTime(nullable: false, precision: 0),
                    })
                .PrimaryKey(t => t.account);
            
            CreateTable(
                "dbo.StudyCourses",
                c => new
                    {
                        StudentId = c.String(nullable: false, maxLength: 20, storeType: "nvarchar"),
                        CourseId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.StudentId, t.CourseId })
                .ForeignKey("dbo.Users", t => t.StudentId, cascadeDelete: true)
                .ForeignKey("dbo.Courses", t => t.CourseId, cascadeDelete: true)
                .Index(t => t.StudentId)
                .Index(t => t.CourseId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Courses", "TeachId", "dbo.Users");
            DropForeignKey("dbo.StudyCourses", "CourseId", "dbo.Courses");
            DropForeignKey("dbo.StudyCourses", "StudentId", "dbo.Users");
            DropIndex("dbo.StudyCourses", new[] { "CourseId" });
            DropIndex("dbo.StudyCourses", new[] { "StudentId" });
            DropIndex("dbo.Courses", new[] { "TeachId" });
            DropTable("dbo.StudyCourses");
            DropTable("dbo.Users");
            DropTable("dbo.Courses");
        }
    }
}
